<template>
    <SelectCategory v-if="planNumberVisible" @confirm="selectConfirm" @cancel="planNumberVisible = false"></SelectCategory>
    <div class="e-form" v-else>
        <div style="width: 100%" class="form">
            <el-form ref="form" :model="formData" label-width="200px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="设备类别：">
                            <el-input v-model="formData.categoryName" readonly>
                                <i slot="suffix" class="el-input__icon el-icon-document-copy" @click="planNumberVisible = true"></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="每公里/小数数量：">
                            <el-input placeholder="请输入内容" v-model="formData.quantityValue"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                    <el-form-item label="保养周期：">
                            <el-select
                                v-model="formData.maintenanceCycle"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="(
                                        item, index
                                    ) in maintenanceCycle"
                                    :key="index"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                            <span>{{ formData.orgName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="是否启用：">
                            <el-checkbox v-model="formData.isEnable"></el-checkbox>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                >保存</el-button
            >
            <el-button size="small" @click="handleClose">取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/equip/equipPlan.js'
import { mapState } from 'vuex'
import SelectCategory from './maintenanceDialog/selectCategory.vue'
export default {
    data () {
        return {
            formData: {
            },
            planNumberVisible: false,
        }
    },
    components: {
        SelectCategory
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            maintenanceCycle: state=>state.equip.equipData.maintenanceCycle
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    created () {
        this.billid = this.$route.query.billid
        this.userId = localStorage.getItem('userId')
        this.getInfo()
    },
    mounted () {
    },
    methods: {
        getInfo () {
            request.maintenancePlanInfo( { id: this.billid } ).then(res=>{
                this.formData = res
            })
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        // 获取最后一个内容区域的高度，计算底部空白
        //保存
        preserve () {
            request.maintenancePlanAdd(this.formData).then(()=>{
                this.clientPop('suc', '保存成功', ()=>{ this.$router.push('/maintenancePlanList') })
            })
        },
        //取消
        handleClose () {
            this.$router.go(-1)
        },
        selectConfirm ( data ) {
            this.formData.categoryName = data.categoryName
            this.formData.categoryId = data.categoryId
            this.planNumberVisible = false
        },
    }
}
</script>

<style lang="scss" scoped>
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
    .left {
      padding: 20px;
      padding-top: 0px;
    }
  } */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
